from rest_framework.permissions import BasePermission


class UrlPermission(BasePermission):

    def has_permission(self, request, view):
        # print("权限判断",request.user.role)
        from django.conf import settings
        permission_dict = settings.PERMISSIONS[request.user.role]
        # 2当前访问的url
        # print(request.resolver_match.url_name,request.method)
        url_name = request.resolver_match.url_name
        # print(url_name)
        method = request.method
        # 3 权限判断
        method_list = permission_dict.get(url_name)
        if not method_list:
            return False
        if method in method_list:
            return True

        return False
